package com.lh.music.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lh.music.R;
import com.lh.music.entity.PaihangEntity;

import java.util.List;

/**
 * Created by a on 2016/12/14.
 */

public class PaihangAdapter extends BaseAdapter {
    private Context context;
    private List<PaihangEntity> mData;

    public PaihangAdapter(Context context, List<PaihangEntity> mData) {
        this.context = context;
        this.mData = mData;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            convertView= LayoutInflater.from(context)
                    .inflate(R.layout.adapter_paihang,null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.type.setText(mData.get(position).getType());
        holder.name1.setText(mData.get(position).getName1());
        holder.name2.setText(mData.get(position).getName2());
        holder.name3.setText(mData.get(position).getName3());
        Glide.with(context)
                .load(mData.get(position).getPicUrl())
                .placeholder(R.mipmap.a9d)
                .crossFade()
                .centerCrop()
                .into(holder.type_icon);
        return convertView;
    }
    static class ViewHolder{
        ImageView type_icon;
        TextView type;
        TextView name1;
        TextView name2;
        TextView name3;
        public ViewHolder(View view){
            type_icon= (ImageView) view.findViewById(R.id.type_icon);
            type= (TextView) view.findViewById(R.id.type);
            name1= (TextView) view.findViewById(R.id.name1);
            name2= (TextView) view.findViewById(R.id.name2);
            name3= (TextView) view.findViewById(R.id.name3);
        }
    }
}
